﻿using AutoMapper;
using Joy.Erp.BasicArchives.Core;

namespace Joy.Erp.BasicArchives.Sales
{
    public class SaleOrderAutoMapperProfile : Profile
    {
        public SaleOrderAutoMapperProfile()
        {
            CreateMap<SaleOrder, SaleOrderDto>().MapExtraProperties().ReverseMap();
            CreateMap<SaleOrder, SaleOrderDocumentDto>().MapExtraProperties().ReverseMap();
            CreateMap<SaleOrder, SaleOrderCreateDto>().MapExtraProperties().ReverseMap();
            CreateMap<SaleOrder, SaleOrderUpdateDto>()
                .MapExtraProperties()
                .ForMember(dest => dest.Children, opt => opt.Ignore());
            CreateMap<SaleOrderUpdateDto, SaleOrder>()
                .MapExtraProperties()
                .ForMember(dest => dest.Id, opt => opt.Ignore())
                .ForMember(dest => dest.OrderType, opt => opt.Ignore())
                .ForMember(dest => dest.Customer, opt => opt.Ignore())
                .ForMember(dest => dest.Operator, opt => opt.Ignore())
                .MapChildren<SaleOrderUpdateDto, SaleOrder, SaleOrderLineCreateOrUpdateDto, SaleOrderLine>();

            CreateMap<SaleOrderLine, SaleOrderLineDto>().MapExtraProperties().ReverseMap();
            CreateMap<SaleOrderLine, SaleOrderLineCreateOrUpdateDto>().MapExtraProperties().ReverseMap();
        }
    }
}